/*
* 综合看板首页
* */

import 'package:center_beijing/api/product_api.dart';
import 'package:center_beijing/api/statistical_analysis_api.dart';
import 'package:center_beijing/common/logutil.dart';
import 'package:center_beijing/common/styles.dart';
import 'package:center_beijing/common/utils.dart';
import 'package:center_beijing/comprehensiveData/daily_indicators.dart';
import 'package:center_beijing/comprehensiveData/order_progress.dart';
import 'package:center_beijing/comprehensiveData/storage_yard_stock.dart';
import 'package:center_beijing/comprehensiveData/task_progress.dart';
import 'package:center_beijing/comprehensiveData/tran_progress.dart';
import 'package:center_beijing/config/global_config.dart';
import 'package:center_beijing/models/selectItem.dart';
import 'package:center_beijing/widgets/custom_loading_widget.dart';
import 'package:center_beijing/widgets/custom_radio.dart';
import 'package:center_beijing/widgets/pull_select_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_echarts/flutter_echarts.dart';
import 'package:flutter_pickers/pickers.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'dart:async';
import 'dart:convert';


class ComprehensiveData extends StatefulWidget {
  @override
  _ComprehensiveDataState createState() => _ComprehensiveDataState();
}

class _ComprehensiveDataState extends State<ComprehensiveData>
    with SingleTickerProviderStateMixin {

  final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
  List navTitle = ['日常指标', '订单进度', '任务进度', '堆场库存', '运输进度'];

  bool chartLoading = true;
  bool flag = false;
  String currentIndexStr = '日常指标';
  var first = DailyIndicators();
  var second =OrderProgress();
  var third = TaskProgress();

  @override
  void initState() {
    super.initState();

  }

  @override
  void dispose() {
    super.dispose();
  }


  getNavItem(item) {
    return GestureDetector(
      onTap: () {
        this.setState(() {
          flag = false;
          currentIndexStr = item;
        });
      },
      child: Container(
        padding: EdgeInsets.fromLTRB(
            Styles.spacing8, Styles.spacing4, Styles.spacing8, Styles.spacing4),
        margin: EdgeInsets.fromLTRB(0, Styles.spacing4, 0, Styles.spacing4),
        decoration: BoxDecoration(
            border: Border.all(
                color: currentIndexStr == item
                    ? Styles.BlueColor
                    : Colors.transparent),
            color:
                currentIndexStr == item ? Styles.BlueColor3 : Styles.GrayLight),
        child: Text(
          item,
          style: TextStyle(
              color: currentIndexStr == item
                  ? Styles.BlueColor
                  : Styles.TitleItemColor,
              fontSize: Styles.NormalFont),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _scaffoldKey,
      appBar: AppBar(
        title: GestureDetector(
          behavior: HitTestBehavior.translucent,
          onTap: () {
            this.setState(() {
              flag = !this.flag;
            });
          },
          child: Container(
            margin: EdgeInsets.only(right: Styles.spacing48),
            alignment: Alignment.center,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Container(
                  alignment: Alignment.center,
                  margin: EdgeInsets.fromLTRB(
                      Styles.spacing4, 0, Styles.spacing4, 0),
                  child: Text(
                    currentIndexStr,
                    style: TextStyle(
                        color: Colors.white, fontSize: Styles.MiddleFont17),
                  ),
                ),
                Image.asset(
                  'assets/images/nav-icon-down.png',
                  width: 8.w,
                  height: 8.h,
                )
              ],
            ),
          ),
        ),
      ),
      body: Container(
        color: Styles.MainBackgroundColor,
        padding:
            EdgeInsets.fromLTRB(0, 0, 0, MediaQuery.of(context).padding.bottom),
        child: Stack(
          alignment: Alignment.center,
          children: [
            currentIndexStr=='日常指标'?first:(currentIndexStr=='订单进度'?second:(currentIndexStr=='堆场库存'?StorageYardStock():(currentIndexStr=='运输进度'?TranProgress():third))),
            flag
                ? Column(
                    children: [
                      Container(
                        padding: EdgeInsets.fromLTRB(
                            0, Styles.spacing16, 0, Styles.spacing16),
                        alignment: Alignment.center,
                        color: Colors.white,
                        child: Wrap(
                          spacing: 10.w, //主轴上子控件的间距
                          runSpacing: 5, //交叉轴上子控件之间的间距
                          children: this.navTitle.map<Widget>((item) {
                            return this.getNavItem(item);
                          }).toList(), //要显示的子控件集合
                        ),
                      ),
                      Expanded(
                          child: GestureDetector(
                        onTap: () {
                          this.setState(() {
                            flag = false;
                          });
                        },
                        child: Container(
                          color: Color.fromRGBO(0, 0, 0, 0.5),
                        ),
                      ))
                    ],
                  )
                : Container(),
          ],
        ),
      ),
    );
  }
}
